<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\common\controller;

use app\common\model\Member;
use thans\jwt\facade\JWTAuth;
use think\App;
use think\exception\ValidateException;
use think\Validate;

/**
 * common
 */
abstract class WxappController
{
    /**
     * Request实例
     * @var \think\Request
     */
    protected $request;

    /**
     * 应用实例
     * @var \think\App
     */
    protected $app;

    /**
     * 是否批量验证
     * @var bool
     */
    protected $batchValidate = false;

    /**
     * 控制器中间件
     * @var array
     */
    protected $middleware = ['app\wxapp\middleware\JWTauthWxapp'];

    protected $user_id      = 0;
    protected $user         = [];
    protected $page         = 1;
    protected $limit        = 15;
    protected $cache_name   = '';


    /**
     * 构造方法
     * @access public
     * @param  App  $app  应用对象
     */
    public function __construct(App $app)
    {
        $this->app     = $app;
        $this->request = $this->app->request;

        // 控制器初始化
        $this->initialize();
    }

    // 初始化
    protected function initialize() {
        $this->page = $this->request->param('page',1);
        $this->limit = $this->request->param('limit',15);

        try{
            $auth_info = JWTAuth::auth();
            $user_id = $auth_info['user_id']->getValue();
            $user_info = Member::where('id',$user_id)->find();
            $this->user_id = $user_info['id'];
            $this->user = $user_info;

        }catch (\Exception $e){

        }
    }
}
